home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Tools / AmigaLib / testcx.e < prev    next >
Text File  |  1995-04-01  |  3KB  |  95 lines

  1. OPT PREPROCESS
  2.  
  3. MODULE 'commodities',
  4.        'amigalib/cx',
  5.        'devices/timer',
  6.        'devices/inputevent',
  7.        'dos/dos',
  8.        'exec/ports',
  9.        'libraries/commodities'
  10.  
  11. ENUM ERR_NONE, ERR_BRKR, ERR_CRCX, ERR_CXERR, ERR_HOT, ERR_LIB, ERR_PORT
  12.  
  13. RAISE ERR_BRKR IF CxBroker()=NIL,
  14.       ERR_CRCX IF CreateCxObj()=NIL,
  15.       ERR_LIB  IF OpenLibrary()=NIL,
  16.       ERR_PORT IF CreateMsgPort()=NIL
  17.  
  18. CONST EVT_HOTKEY=1
  19.  
  20. DEF broker_mp=NIL:PTR TO mp, broker=NIL, cxsigflag, ie:PTR TO inputevent
  21.  
  22. PROC main() HANDLE
  23.   DEF hotkey, msg, newshell
  24.   newshell:='newshell\b'
  25.   cxbase:=OpenLibrary('commodities.library', 37)
  26.   broker_mp:=CreateMsgPort()
  27.   cxsigflag:=Shl(1, broker_mp.sigbit)
  28.  
  29.   broker:=CxBroker([NB_VERSION, 0,
  30.                    'HotKey', 'Little Hotkey', 'A little hot key commodity',
  31.                     NBU_UNIQUE OR NBU_NOTIFY,
  32.                     0, 0, 0, broker_mp, 0]:newbroker, NIL)
  33.  
  34.   IF hotkey:=hotKey('rawkey control f1', broker_mp, EVT_HOTKEY)
  35.     AttachCxObj(broker, hotkey)
  36.     IF CxObjError(hotkey)<>FALSE
  37.       Raise(ERR_CXERR)
  38.     ELSE
  39.       IF ie:=invertStringRev(newshell, NIL)
  40.         ActivateCxObj(broker, TRUE)
  41.         processMsg()
  42.         freeIEvents(ie)
  43.       ENDIF
  44.     ENDIF
  45.   ELSE
  46.     Raise(ERR_HOT)
  47.   ENDIF
  48. EXCEPT DO
  49.   IF broker THEN DeleteCxObjAll(broker)
  50.   IF broker_mp
  51.     WHILE msg:=GetMsg(broker_mp) DO ReplyMsg(msg)
  52.     DeleteMsgPort(broker_mp)
  53.   ENDIF
  54.   IF cxbase THEN CloseLibrary(cxbase)
  55.   SELECT exception
  56.   CASE ERR_BRKR;   WriteF('Error: Could not create broker\n')
  57.   CASE ERR_CRCX;   WriteF('Error: Could not create CX object\n')
  58.   CASE ERR_CXERR;  WriteF('Error: Could not activate broker\n')
  59.   CASE ERR_HOT;    WriteF('Error: Could not create hot key\n')
  60.   CASE ERR_LIB;    WriteF('Error: Could not open required library\n')
  61.   CASE ERR_PORT;   WriteF('Error: Could not create message port\n')
  62.   ENDSELECT
  63. ENDPROC
  64.  
  65. PROC processMsg()
  66.   DEF msg, sigrcvd, msgid, msgtype, going=TRUE
  67.   WHILE going
  68.     sigrcvd:=Wait(SIGBREAKF_CTRL_C OR cxsigflag)
  69.     WHILE msg:=GetMsg(broker_mp)
  70.       msgid:=CxMsgID(msg)
  71.       msgtype:=CxMsgType(msg)
  72.       ReplyMsg(msg)
  73.       SELECT msgtype
  74.       CASE CXM_IEVENT
  75.         IF msgid=EVT_HOTKEY
  76.           WriteF('You hit the HotKey -- adding input events\n')
  77.           AddIEvents(ie)
  78.         ENDIF
  79.       CASE CXM_COMMAND
  80.         SELECT msgid
  81.         CASE CXCMD_DISABLE
  82.           ActivateCxObj(broker, FALSE)
  83.         CASE CXCMD_ENABLE
  84.           ActivateCxObj(broker, TRUE)
  85.         CASE CXCMD_KILL
  86.           going:=FALSE
  87.         CASE CXCMD_UNIQUE
  88.           going:=FALSE
  89.         ENDSELECT
  90.       ENDSELECT
  91.     ENDWHILE
  92.     IF sigrcvd AND SIGBREAKF_CTRL_C THEN going:=FALSE
  93.   ENDWHILE
  94. ENDPROC
  95.